package com.javaspeak.algorithm.deletedirectory.nonrecursive;

import java.io.File;
import java.io.IOException;


import org.junit.Test;
import static org.junit.Assert.*;


/**
 * @author John Dickerson
 */
public class DeleteFilesTest {

    @Test
    public void testDeleteFiles() throws IOException {

        String tempDirStr = System.getProperty( "java.io.tmpdir" );

        File tempDir = new File( tempDirStr );
        File testDirectory =  new File( tempDir, "DeleteFilesTest" );

        if ( ! testDirectory.exists() ){

            testDirectory.mkdir();
        }

        File a = new File( testDirectory, "a.txt" );

        if ( ! a.exists() ){

            a.createNewFile();
        }

        File bDir = new File( testDirectory, "bDir" );

        if ( ! bDir.exists() ){

            bDir.mkdir();
        }

        File c = new File( bDir, "c.txt" );

        if ( ! c.exists() ){

            c.createNewFile();
        }

        File d = new File( bDir, "d.txt" );

        if ( ! d.exists() ){

            d.createNewFile();
        }

        DeleteFiles.deleteFiles( testDirectory );

        assertTrue( ! testDirectory.exists() );
    }
}
